#include "sth20.h"
#include "drv_IIC.h"
#include "drv_systick.h"
#define ACK 0
#define NOACK 1
sth20_value value;

void drv_sth20_init()
{
	drv_IIC_init();
	
	
}
uint16_t drv_sth20_read()
{
	uint8_t date[2];
	uint16_t receive_date;
	drv_IIC_start();//起始信号
	drv_ICC_senddate(0x80);//发送地址
	if(drv_IIC_waitACK()!=ACK)
		{
			return NOACK;
		}
		drv_ICC_senddate(0xE3);//发送数据
		if(drv_IIC_waitACK()!=ACK)
		{
			return NOACK;
		}
	drv_IIC_start();//起始信号
	drv_IIC_readdate(0x81);
	if(drv_IIC_waitACK()!=ACK)
		{
			return NOACK;
		}
	delay_ms(85);
	date[0]=drv_IIC_readdate(ACK);
	date[1]=drv_IIC_readdate(NOACK);
	receive_date=((date[0]<<8)|date[1]);
	return receive_date;
}
void drv_sth20_getdate(void)
{
	uint16_t receive;
	receive=drv_sth20_read();
	value.tem=-46.85+175.72*((float)receive/65536);
	printf("tempeture=%.2f\r\n",value.tem);
}
